package org.jeecg.modules.xl.order.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.xl.h5api.vo.CornerNum;
import org.jeecg.modules.xl.order.dto.OrderDetailNew;
import org.jeecg.modules.xl.order.entity.XlCustomerOrderDetail;
import org.jeecg.modules.xl.order.mapper.XlCustomerOrderDetailMapper;
import org.jeecg.modules.xl.order.service.IXlCustomerOrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: xl_customer_order_detail
 * @Author: jeecg-boot
 * @Date:   2024-10-20
 * @Version: V1.0
 */
@Service
public class XlCustomerOrderDetailServiceImpl extends ServiceImpl<XlCustomerOrderDetailMapper, XlCustomerOrderDetail> implements IXlCustomerOrderDetailService {
	
	@Autowired
	private XlCustomerOrderDetailMapper xlCustomerOrderDetailMapper;
	@Value("${pichost}")
	private String baseUrl;

	@Override
	public List<XlCustomerOrderDetail> selectByMainId(String mainId) {
		//拼接图片
		List<XlCustomerOrderDetail> xlCustomerOrderDetailList = new ArrayList<>();
		xlCustomerOrderDetailList.addAll(xlCustomerOrderDetailMapper.selectByMainId(mainId));

		//String baseUrl = "http://47.93.163.105:8058/jeecg-boot/sys/common/static/";
		List<XlCustomerOrderDetail> newRecordsList = new ArrayList<>();
		for(XlCustomerOrderDetail xlCustomerOrderDetail : xlCustomerOrderDetailList){
			if(ObjectUtil.isNotEmpty(xlCustomerOrderDetail.getMainPic())) {
				xlCustomerOrderDetail.setMainPic(baseUrl + xlCustomerOrderDetail.getMainPic());
			}else{
				xlCustomerOrderDetail.setMainPic(baseUrl+ "/temp/nophoto.png");
			}
			newRecordsList.add(xlCustomerOrderDetail);
		}
		return newRecordsList ;
	}

    @Override
    public List<XlCustomerOrderDetail> queryOrderDetailNotShipmentById(String id) {
        return xlCustomerOrderDetailMapper.queryOrderDetailNotShipmentById(id);
    }

	@Override
	public List<OrderDetailNew> queryNewOrderDetail(String ordercode) {

		//拼接图片
		List<OrderDetailNew> xlCustomerOrderDetailList = new ArrayList<>();

		xlCustomerOrderDetailList.addAll(xlCustomerOrderDetailMapper.queryNewOrderDetailByOrderCode(ordercode));

		//String baseUrl = "http://47.93.163.105:8058/jeecg-boot/sys/common/static/";
		List<OrderDetailNew> newRecordsList = new ArrayList<>();

		for(OrderDetailNew xlCustomerOrderDetail : xlCustomerOrderDetailList){
			if(ObjectUtil.isNotEmpty(xlCustomerOrderDetail.getMainPic())) {
				if(!xlCustomerOrderDetail.getMainPic().contains(baseUrl)){
					xlCustomerOrderDetail.setMainPic(baseUrl + xlCustomerOrderDetail.getMainPic());
				}

			}else{
				xlCustomerOrderDetail.setMainPic(baseUrl+ "/temp/nophoto.png");
			}
			newRecordsList.add(xlCustomerOrderDetail);
		}
		return newRecordsList ;
	}

	@Override
	public List<CornerNum> getCornerNum(String mystoreStr) {
		return null; // baseMapper.getCornerNum(mystoreStr);
	}

}
